<?php

/**
 * SvnFile class.
 *
 *
 * @package    lib
 * @subpackage lib_svn
 * @author     Juan Carlos Jarquin (zetta)
 * @author     $LastChangedBy$
 * @version    0.2, SVN: $Id$
 */

class SvnFile
{
  
  const VERSION = '0.2-dev';
  
  /**
   * @var string
   */
  private $url = '';
  
  /**
   * @var string
   */
  private $baseUrl = '';
  
  /**
   * @var Svn
   */
  private $svn = null;
  /**
   * Class Constructor
   * @param string $url
   * @return SvnFile
   */
  public function SvnFile($url = null)
  {
    $this->svn = new Svn();
    if (is_null($url))
      $this->analyzeUrl();
    else $this->url = $url;
    $this->fetchData();
  }
  
  /**
   * Analiza la url que se envio en REQUEST_URI para poder determinar que archivo se va a modificar
   */
  private function analyzeUrl()
  {
    $xml = simplexml_load_file('data/config.xml');
    $request = Request::getInstance();
    $base = $xml->{'svn-url'};
    $url = str_replace($request->getBaseUrl(), '', $request->getPathInfo());
    $url = str_replace('/' . $request->getControllerName(), '', $url);
    $this->url = $base . $url;
  }
  
  /**
   * Fetch svn file data
   */
  private function fetchData()
  {
    $this->info = $this->svn->getFileInformation($this->url);
  }

}